package com.yycx.module.file.provider.listener.subscribe;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.constants.QueueConstants;
import com.yycx.module.file.client.entity.SysFile;
import com.yycx.module.file.provider.enums.StoreTypeEnum;
import com.yycx.module.file.provider.service.OssUploadService;
import com.yycx.module.file.provider.service.SysFileService;
import com.yycx.starter.rabbitmq.config.RabbitComponent;
import com.yycx.starter.rabbitmq.core.BaseRabbiMqHandler;
import com.yycx.starter.rabbitmq.listener.MqListener;
import com.rabbitmq.client.Channel;
import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;

import java.io.InputStream;
import java.util.Map;

/**
 * 上传文件到OSS
 *
 * @author zyf
 */
@RabbitComponent(value = "uploadRabbitMqListener")
@AllArgsConstructor
public class UploadRabbitMqListener extends BaseRabbiMqHandler<EntityMap> {

    private final SysFileService sysFileService;

    @RabbitListener(queues = QueueConstants.QUEUE_UPLOADOSS)
    public void onMessage(EntityMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
        super.onMessage(baseMap, deliveryTag, channel, new MqListener<EntityMap>() {
            @Override
            public void handler(EntityMap map, Channel channel) {
                sysFileService.uploadByMq(map, channel);
            }
        });
    }

}
